package com.proyecto.track.action;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.proyecto.track.bo.Account;
import com.proyecto.track.service.UserPersonService;

public class InicioAction extends ActionSupport{
	private static final long serialVersionUID = 1L;

	@Autowired
	private UserPersonService userPersonService;

	public String inicio() {
		String userName = SecurityContextHolder.getContext()
				.getAuthentication().getName();
		Account account = userPersonService.searchAccount(userName);

		Map<String,Object> session = ActionContext.getContext().getSession();
		session.put("accountId", account.getId());
		session.put("accountName", account.getUserName());

		//Ej de como recuperar el usuario desde session....
		//Usuario usuario = (Usuario) session.get("usuario");
		
		return SUCCESS;
	}
	
	public String logOut(){
		Map<String,Object> session = ActionContext.getContext().getSession();
		session.clear();
		return SUCCESS;
	}

	public UserPersonService getUserPersonService() {
		return userPersonService;
	}

	public void setUserPersonService(UserPersonService userPersonService) {
		this.userPersonService = userPersonService;
	}

	
}
